package com.huatai.vba.file.dbf;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.linuxense.javadbf.DBFField;

public class DBFObject {

	public DBFObject() {
	}

	public DBFObject(String fileName, DBFField[] fields, Object[] data) {
		this.fileName = fileName;
		this.fields = fields;
		this.data = data;
	}

	private String fileName;

	private DBFField[] fields;

	private Object[] data;

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public DBFField[] getFields() {
		return fields;
	}

	public void setFields(DBFField[] fields) {
		this.fields = fields;
	}

	public Object[] getData() {
		return data;
	}

	public void setData(Object[] data) {
		this.data = data;
	}

	public List<Map<String, Object>> getResultList() {
		if (data == null || data.length == 0 || fields == null || fields.length == 0)
			return null;
		List<Map<String, Object>> list = Lists.newArrayList();
		for (int i = 0; i < data.length; i++) {
			Object[] o = (Object[]) data[i];
			Map<String, Object> map = Maps.newHashMap();
			for (int j = 0; j < fields.length; j++) {
				map.put(fields[j].getName().toLowerCase(), o[j]);
			}
			list.add(map);
		}
		return list;
	}

}
